home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / part.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  2KB  |  66 lines

  1. /* Copyright (C) 2000-1 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: part.c,v 1.22 2001/02/15 08:39:45 drscholl Exp $ */
  6.  
  7. #include <string.h>
  8. #include "opennap.h"
  9. #include "debug.h"
  10.  
  11. /* 401 [ :<nick> ] <channel>
  12.  * this function handles the PART(401) command from clients
  13.  */
  14. HANDLER (part)
  15. {
  16.     CHANNEL *chan = 0;
  17.     USER *user;
  18.     char *sender_name;
  19.     char *arg;
  20.  
  21.     (void) len;
  22.     ASSERT (validate_connection (con));
  23.  
  24.     if (pop_user_server (con, tag, &pkt, &sender_name, &user) != 0)
  25.     return;
  26.     ASSERT (validate_user (user));
  27.  
  28.     if (!(arg = next_arg (&pkt)))
  29.     {
  30.     unparsable (con);
  31.     return;
  32.     }
  33.  
  34.     /* find the requested channel in the user's  list */
  35.     if (!(chan = find_channel (user->channels, arg)))
  36.     {
  37.     if (ISUSER (con))
  38.         send_cmd (con, MSG_SERVER_NOSUCH,
  39.             "part channel failed: you are not in that channel");
  40.     else
  41.         log ("part: %s is not on channel %s (from %s)", user->nick, arg,
  42.             con->host);
  43.     return;
  44.     }
  45.  
  46.     /* ack the user */
  47.     if (ISUSER (con))
  48.     send_cmd (con, tag, "%s", chan->name);
  49.  
  50.     if (!chan->local)
  51.     {
  52.     /* NOTE: we use the MSG_CLIENT_PART(401) message instead of
  53.        passing MSG_SERVER_PART(407) to pass between servers because we
  54.        can reuse this same function for both messages easier than
  55.        implementing support for parsing the latter.  The 401 message
  56.        will be translated into a 407 for sending to end users. */
  57.     pass_message_args (con, MSG_CLIENT_PART, ":%s %s", user->nick,
  58.         chan->name);
  59.     }
  60.  
  61.     user->channels = list_delete (user->channels, chan);
  62.  
  63.     /* remove user from the channel members list and notify local clients */
  64.     part_channel (chan, user);
  65. }
  66.